//
//  LZCAlertView.m
//  mingkang
//
//  Created by Macx on 2017/3/8.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "LZCAlertView.h"
#import "UIView+LZCView.h"
#import <ImSDK/ImSDK.h>
#import "NSString+Common.h"
#import "AdministratorListViewController.h"

#import "HomeServer.h"
#import "PushPerHome.h"
#import "UIView+LZCView.h"
#import "ShopHomeViewController.h"

@interface LZCAlertView()

@property (nonatomic, assign) BOOL judge;
@property (nonatomic, strong) id userInfo;
@property (nonatomic, strong) UIView *alertview;

@property (nonatomic, strong) NSArray *bottomArr;

@property (nonatomic, strong) NSString *hostId; // 当前直播间用户
@property (nonatomic, strong) NSString *groupId;
@property (nonatomic, strong) NSString *currUserId; // 当前手机用户

@property (nonatomic, strong) NSMutableArray *alertArr;

@end

@implementation LZCAlertView


- (id)initWithFrame:(CGRect)frame
{
    
    self = [super initWithFrame:frame];
    if (self) {
        
        //创建遮罩
        UIView *mask = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height)];
        [self addSubview:mask];
        mask.backgroundColor = [UIColor clearColor];
        [mask addTarget:self action:@selector(maskClick)];
        
        //创建alert
        self.alertview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-60, 10)];
        self.alertview.layer.cornerRadius = 5;
        self.alertview.clipsToBounds = YES;
        self.alertview.backgroundColor = [UIColor whiteColor];
        [self addSubview:_alertview];
        [self exChangeOut:self.alertview dur:0.2];

    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    // 第二次就不需要重新创建
    if (self.judge == 0) {
    
        CGFloat width = self.alertview.width;
        
        // 头部举报拉黑
//        NSArray *topArr = @[@[@"live_report", @"举报"], @[@"live_defriend", @"拉黑"], @[@"placeHolder", @"管理"],@[@"placeHolder", @"禁言"]];
        CGSize topSize = [LZCTools textSizeWithText:@"字数" font:kUHSystemFontWithSize(11)];
//        for (int i = 0; i < topArr.count; i++) {
//            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10+(15+2+topSize.height+topSize.width)*i, 10, topSize.height, topSize.height)];
//            [self.alertview addSubview:imageView];
//            imageView.image = [UIImage imageNamed:topArr[i][0]];
//            
//            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
//            btn.frame = CGRectMake(12+topSize.height+(15+2+topSize.height+topSize.width)*i, 0, topSize.width, topSize.height+20);
//            [self.alertview addSubview:btn];
//            [btn setTitle:topArr[i][1] forState:UIControlStateNormal];
//            [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
//            btn.titleLabel.font = kUHSystemFontWithSize(11);
//            btn.tag = 1+i;
//            
//            [btn addTarget:self action:@selector(reportAction:) forControlEvents:UIControlEventTouchUpInside];
//        }
        self.hostId = [GetUserDefaule(CURRLIVE) valueForKey:@"hostId"];
        self.groupId = [GetUserDefaule(CURRLIVE) valueForKey:@"groupId"];
        self.currUserId = [GetUserDefaule(USERINFO) valueForKey:@"user_id"];
        
        // 如果是主播，开放所有，如果是管理员并且点击的不是主播
        // 当前用户是主播或者当前用户不是点自己的头像
		NSLog(@"hostId is %@, selfId is %@, clicked id is %@", self.hostId, self.currUserId, self.userInfo[@"user_id"]);
        
        // close
        UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.alertview addSubview:closeBtn];
        [closeBtn setImage:[UIImage imageNamed:@"live_zhubo_close"] forState:UIControlStateNormal];
        closeBtn.frame = CGRectMake(width-20-topSize.height, 0, 20+topSize.height, 20+topSize.height);
        [closeBtn addTarget:self action:@selector(maskClick) forControlEvents:UIControlEventTouchUpInside];
        
        // 头像
        UIImageView *headPic = [[UIImageView alloc] initWithFrame:CGRectMake((width-SW(5))/2 , closeBtn.y+closeBtn.height, SW(5), SW(5))];
        [self.alertview addSubview:headPic];
        headPic.layer.cornerRadius = SW(10);
        headPic.layer.masksToBounds = YES;
        headPic.contentMode = UIViewContentModeScaleAspectFill;
        [headPic sd_setImageWithURL:[NSURL URLWithString:self.userInfo[@"face"]] placeholderImage:[UIImage imageNamed:@"placeHolder.png"]];
        
        UIImageView *levelPic = [[UIImageView alloc] initWithFrame:CGRectMake(headPic.x+headPic.width-SW(15), headPic.y+headPic.height-SW(15), SW(15), SW(15))];
        [self.alertview addSubview:levelPic];
//        levelPic.image = [UIImage imageNamed:@"level"];
//        if ([self.userInfo[@"is_enterprise"] isEqualToString:@"1"]) {
//        levelPic.image = IMAGE(@"placeHolder");
//        }
		int role = [self.userInfo[@"role"] intValue];
		if (role == 3 || role == 4 || role == 6) {
			levelPic.image = IMAGE(@"icon_add_v");
		}
        
        UILabel *userName = [[UILabel alloc] init];
        [self.alertview addSubview:userName];
        userName.text = self.userInfo[@"nickname"];
        userName.textAlignment = NSTextAlignmentCenter;
        userName.textColor = [UIColor grayColor];
        userName.font = kUHSystemFontWithSize(11);
        CGSize userNameSize = [LZCTools textSizeWithText:userName.text font:userName.font];
        userName.frame = CGRectMake((width-userNameSize.width)/2, headPic.y+headPic.height+SW(40), userNameSize.width, userNameSize.height);
        
        UIImageView *gender = [[UIImageView alloc] initWithFrame:CGRectMake(width/2-2-SW(20), userName.y+userName.height+SW(40), SW(20), SW(20))];
        [self.alertview addSubview:gender];
        if ([self.userInfo[@"sex"] isEqualToString:@"1"]) {
            gender.image = IMAGE(@"sex_boy");
        }
        else
            gender.image = IMAGE(@"sex_girl");

        
        UIButton *vipBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.alertview addSubview:vipBtn];
        vipBtn.userInteractionEnabled = NO;
        [vipBtn setBackgroundImage:[UIImage imageNamed:@"level_bg"] forState:UIControlStateNormal];
        [vipBtn setImage:[UIImage imageNamed:@"level_star"] forState:UIControlStateNormal];
        [vipBtn setTitle:[NSString stringWithFormat:@" %@", self.userInfo[@"level"]] forState:UIControlStateNormal];
        vipBtn.titleLabel.font = kUHSystemFontWithSize(10);
        [vipBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        CGSize vipSize = [LZCTools textSizeWithText:vipBtn.titleLabel.text font:kUHSystemFontWithSize(10)];
        vipBtn.frame = CGRectMake(width/2+2, userName.y+userName.height+SW(40), vipSize.width+5+SW(20), SW(20));
        
        // id行
        UILabel *userID = [[UILabel alloc] init];
        [self.alertview addSubview:userID];
        userID.text = [NSString stringWithFormat:@"ID号：%@", self.userInfo[@"user_id"]];
        userID.textAlignment = NSTextAlignmentRight;
        userID.textColor = [UIColor grayColor];
        userID.font = kUHSystemFontWithSize(11);
        CGSize userIDSize = [LZCTools textSizeWithText:userID.text font:userID.font];
        
        userID.frame = CGRectMake(0, gender.y+gender.height+SW(40), width/2-2, userIDSize.height);
        
        UIButton *location = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.alertview addSubview:location];
        location.userInteractionEnabled = NO;
        [location setImage:[UIImage imageNamed:@"live_gps"] forState:UIControlStateNormal];
        [location setTitle:@" 广州" forState:UIControlStateNormal];
        location.titleLabel.font = kUHSystemFontWithSize(11);
        [location setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        location.frame = CGRectMake(width/2+2, gender.y+gender.height+SW(40), topSize.width+topSize.height+5, userIDSize.height);
        
        UILabel *Introduction = [[UILabel alloc] init];
        [self.alertview addSubview:Introduction];
//        Introduction.text = @"xxxxx";
        Introduction.text = self.userInfo[@"intro"];
        //    liveTime.text = [NSString stringWithFormat:@"直播时长：%@", self.liveDuration];
        Introduction.textColor = [UIColor grayColor];
        Introduction.textAlignment = NSTextAlignmentCenter;
        Introduction.font = kUHSystemFontWithSize(11);
        Introduction.numberOfLines = 1;
        CGSize IntroductionSize = [LZCTools textSizeWithText:Introduction.text font:Introduction.font];
        Introduction.frame = CGRectMake((width-IntroductionSize.width)/2, userID.y+userID.height+SW(40), IntroductionSize.width, IntroductionSize.height);
        if (IntroductionSize.width > width-20) {
            Introduction.frame = CGRectMake(10, userID.y+userID.height+SW(40), width-20, IntroductionSize.height);
        }
//        CGSize IntroductionSize = [Introduction sizeThatFits:CGSizeMake(width-20, MAXFLOAT)];
//        Introduction.frame = CGRectMake(10, userID.y+userID.height+5, width-20, IntroductionSize.height);
        
        NSArray *fArr = @[@"关注", @"粉丝", @"收礼", @"送礼"];
        NSString *value1 = [NSString stringWithFormat:@"%@", self.userInfo[@"following_count"]];
        NSString *value2 = [NSString stringWithFormat:@"%@", self.userInfo[@"followers_count"]];
        NSString *value3 = [NSString stringWithFormat:@"%@", self.userInfo[@"contribution"]];
        NSString *value4 = [NSString stringWithFormat:@"%@", self.userInfo[@"star"]];
        NSArray *valueArr = @[value1, value2, value3, value4];
        for (int i = 0; i < fArr.count; i++) {
            UIView *view = [self createColumn:fArr[i] value:valueArr[i]];
            [self.alertview addSubview:view];
            view.frame = CGRectMake(width/4 * i, Introduction.y+Introduction.height+SW(20), width/4, [LZCTools textSizeWithText:@"字数" font:kUHSystemFontWithSize(11)].height*2+10);
            view.tag = 21+i;
        }
        
        UIView *view = [self viewWithTag:21];
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, view.y+view.height+5, width, 1)];
        [self.alertview addSubview:line];
        line.backgroundColor = [UIColor lightGrayColor];
        line.alpha = 0.5;

        //    CGFloat imgW = (SCREEN_WIDTH-80)/5;
        CGFloat imgY = 0.0;
        CGSize btnSize = [LZCTools textSizeWithText:@"字数" font:kUHSystemFontWithSize(13)];
        
        NSString *btnText1;
        if ([[NSString stringWithFormat:@"%@", self.userInfo[@"is_like"]] isEqualToString:@"1"]) {
            btnText1 = @"已关注";
        }
        else
            btnText1 = @"关注";
        self.bottomArr = @[btnText1, @"管理", @"私信", @"主页"];
        for (int i = 0; i < self.bottomArr.count; i++) {
            
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            [self.alertview addSubview:btn];
//            btn.titleLabel.text = self.bottomArr[i];
            [btn setTitle:self.bottomArr[i] forState:UIControlStateNormal];
            btn.titleLabel.font = kUHSystemFontWithSize(13);
//            btn.titleLabel.textColor = [UIColor grayColor];
            [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            btn.frame = CGRectMake(width/4*i, line.y+11, width/4, btnSize.height);
            btn.tag = 31+i;
            imgY = btn.y+btn.height;
            [btn addTarget:self action:@selector(bottomAction:) forControlEvents:UIControlEventTouchUpInside];
            
            UIView *Vline1 = [[UIView alloc] initWithFrame:CGRectMake(width/4*(i+1), line.y+11, 1, btnSize.height)];
            [self.alertview addSubview:Vline1];
            Vline1.backgroundColor = [UIColor lightGrayColor];
            
        }
        
        self.alertview.frame = CGRectMake(0, 0, SCREEN_WIDTH-60, imgY+10);
        self.alertview.center = self.center;
        
    }
    self.judge = 1;
    
}


// 构建礼物和观看人数视图
- (UIView *)createColumn:(NSString *)column value:(NSString *)value {
    
    UIView *bgView = [[UIView alloc] init];
    CGFloat width = self.alertview.width/4;
    
    CGSize textSize = [LZCTools textSizeWithText:column font:kUHSystemFontWithSize(11)];
    
    UILabel *num = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, textSize.height)];
    [bgView addSubview:num];
    num.textColor = [UIColor grayColor];
    num.font = kUHSystemFontWithSize(11);
    num.text = value;
    num.textAlignment = NSTextAlignmentCenter;
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, textSize.height+SW(40), width, textSize.height)];
    [bgView addSubview:label];
    label.textColor = [UIColor lightGrayColor];
    label.font = kUHSystemFontWithSize(11);
    label.text = column;
    label.textAlignment = NSTextAlignmentCenter;
    
    return bgView;
}


#pragma mark ==========响应方法==========
/**
 底部按钮响应
 */
- (void)bottomAction:(UIButton *)sender {
    
    //    UITapGestureRecognizer *tapRecognizer = (UITapGestureRecognizer *)sender;
    NSLog (@"%ld", sender.tag);
	
	//获取当前自己是不是管理员
	NSInteger isSelfAdmin = [GetUserDefaule(SelfAdmin) integerValue];
    switch (sender.tag) {
        case 31:
        {
            NSLog(@"%@被点击", self.bottomArr[0]);
            
            NSString *toUid = [NSString stringWithFormat:@"%@", self.userInfo[@"user_id"]];
            NSDictionary *param = @{@"to":toUid};
            
            if ([sender.titleLabel.text isEqualToString:@"关注"]) {
                [[NetworkTool sharedTool] requestWithName:@"关注" URLString:APIFavorites parameters:param method:@"POST" callBack:^(id responseObject) {
                    [sender setTitle:@"已关注" forState:UIControlStateNormal];
                    
                    // 如果是主播，就发送通知，让主播显示某人关注了他
                    if ([self.hostId isEqualToString:toUid]) {
                        NSDictionary *infoDict = @{@"imId":self.userInfo[@"user_id"],
                                                   @"uid":self.userInfo[@"user_id"],
                                                   @"nickname":self.userInfo[@"nickname"],
                                                   @"headpic":self.userInfo[@"face"],
                                                   @"level":[NSString stringWithFormat:@"%@", self.userInfo[@"level"]]};
                        
                        NSError *parseError = nil;
                        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:infoDict options:NSJSONWritingPrettyPrinted error:&parseError];
                        NSString *infoStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
                        
                        // 发送私聊消息通知
                        NSNotification *notification =[NSNotification notificationWithName:@"SendFavoritesMsg" object:nil userInfo:@{@"receiveInfo":infoStr}];
                        //通过通知中心发送通知
                        [[NSNotificationCenter defaultCenter] postNotification:notification];
                    }
                }];
            }
            else {
                NSString *url = [NSString stringWithFormat:@"%@/%@", APIFavorites, self.userInfo[@"user_id"]];
                [[NetworkTool sharedTool] requestWithName:@"取消关注" URLString:url parameters:nil method:@"DELETE" callBack:^(id responseObject) {
                    [sender setTitle:@"关注" forState:UIControlStateNormal];
                }];
            }
        }
            break;
        case 32:
        {
			if ([self.hostId isEqualToString:self.currUserId] ||
				(![self.userInfo[@"user_id"] isEqualToString:self.currUserId] &&
				 ![self.userInfo[@"user_id"] isEqualToString:self.hostId] &&
				 [self.userInfo[@"is_admin"] isEqual:@0] &&
				 isSelfAdmin == 1)) {
					[self managementClick:sender];
				}
			else {
				[LZCTools HUDMessage:@"您没有管理员权限" delay:1.0];
			}
        }
            break;
        case 33:
        {
            
            [self maskClick];
            
            NSLog(@"%@被点击", self.bottomArr[2]);
            NSString *role;
            // 如果是房主操作就发送到Push
            if ([self.hostId isEqualToString:[GetUserDefaule(USERINFO) valueForKey:@"user_id"]]) {
                role = @"sendPrivateChatMsg0";
            }
            else {
                role = @"sendPrivateChatMsg1";
            }
            
            NSDictionary *infoDict = @{@"imId":self.userInfo[@"user_id"],
                                       @"uid":self.userInfo[@"user_id"],
                                       @"nickname":self.userInfo[@"nickname"],
                                       @"headpic":self.userInfo[@"face"],
                                       @"level":[NSString stringWithFormat:@"%@", self.userInfo[@"level"]]};
            
            NSError *parseError = nil;
            NSData *jsonData = [NSJSONSerialization dataWithJSONObject:infoDict options:NSJSONWritingPrettyPrinted error:&parseError];
            NSString *infoStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
            
            // 发送私聊消息通知
            NSNotification *notification =[NSNotification notificationWithName:role object:nil userInfo:@{@"receiveInfo":infoStr}];
            //通过通知中心发送通知
            [[NSNotificationCenter defaultCenter] postNotification:notification];
            
            
        }
            break;
        case 34:
        {
            NSLog(@"%@被点击", self.bottomArr[3]);
            
//            [LZCTools HUDMessage:@"暂未开放该功能" delay:1.0f];
//            UIViewController *currVC = [self topViewControllerWithRootViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
            
            NSDictionary *user = @{@"is_blocked":self.userInfo[@"is_blocked"],
                                   @"user_id":self.userInfo[@"user_id"],
                                   @"face":self.userInfo[@"face"],
                                   @"nickname":self.userInfo[@"nickname"],
                                   @"role":self.userInfo[@"role"],
                                   @"sex":self.userInfo[@"sex"],
                                   @"is_like":self.userInfo[@"is_like"],
                                   @"level":[NSString stringWithFormat:@"%@", self.userInfo[@"level"]],
                                   @"pro_intro":self.userInfo[@"pro_intro"]};
			
			//只有点击主播的头像才可以跳转
			if (self.isHostClicked) {
				ShopHomeViewController *vc = [[ShopHomeViewController alloc] init];
				vc.isFromLive = YES;
				NSLog(@"userID is %@", self.userInfo[@"user_id"]);
				vc.userId = self.userInfo[@"user_id"];
				UIViewController *currVC = [self topViewControllerWithRootViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
				[currVC.navigationController pushViewController:vc animated:YES];
			}
			
            
//            PerHomeViewController *homeVC = [[PerHomeViewController alloc] init];
//            homeVC.userInfo = user;
//                    
//            [currVC.navigationController pushViewController:homeVC animated:YES];
            
        }
            break;
            
        default:
            break;
    }
    
}

- (void)managementClick:(UIButton *)sender {
    
    UIViewController *currVC = [self topViewControllerWithRootViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"请选择管理类型" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    // 如果是房主本人，开放所有权限
    if ([self.hostId isEqualToString:[GetUserDefaule(USERINFO) valueForKey:@"user_id"]]) {
        
        [alert addAction:[UIAlertAction actionWithTitle:self.alertArr[0] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            AdministratorListViewController *adVC = [[AdministratorListViewController alloc] init];
            adVC.hostId = self.hostId;
            [currVC.navigationController pushViewController:adVC animated:YES];
            
        }]];
        [alert addAction:[UIAlertAction actionWithTitle:self.alertArr[1] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            if ([self.alertArr[1] isEqualToString:@"解除管理员"]) {
                // DELETE /users/{anchor_id}/lives/admins/{user_id} 删除主播管理员 anchor_id *主播ID user_id *管理员ID
                NSString *url = [NSString stringWithFormat:@"%@/%@/lives/admins/%@", APIUser, self.hostId, self.userInfo[@"user_id"]];
                [[NetworkTool sharedTool] requestWithName:@"删除主播管理员" URLString:url parameters:nil method:@"DELETE" callBack:^(id responseObject) {
                    
//                    [self.alertArr insertObject:@"设置管理员" atIndex:1];
                    [self.alertArr replaceObjectAtIndex:1 withObject:@"设置管理员"];
                    
                    // 发送解除管理员消息通知
                    NSNotification *notification =[NSNotification notificationWithName:@"sendDeleteAdministratorMsg" object:nil userInfo:@{@"id":self.userInfo[@"user_id"]}];
                    //通过通知中心发送通知
                    [[NSNotificationCenter defaultCenter] postNotification:notification];
                    
                }];
            }
            else {
                // POST /users/{id}/lives/admins 邀请用户成为自己的管理员 id *主播ID to *被邀人ID
                NSString *url = [NSString stringWithFormat:@"%@/%@/lives/admins", APIUser, [GetUserDefaule(USERINFO) valueForKey:@"user_id"]];
                [[NetworkTool sharedTool] requestWithName:@"邀请管理员" URLString:url parameters:@{@"to":[self.userInfo valueForKey:@"user_id"]} method:@"POST" callBack:^(id responseObject) {
                    
//                    [self.alertArr insertObject:@"解除管理员" atIndex:1];
                    [self.alertArr replaceObjectAtIndex:1 withObject:@"解除管理员"];
                    
                    // 发送设置管理员消息通知
                    NSNotification *notification =[NSNotification notificationWithName:@"sendSetAdministratorMsg" object:nil userInfo:@{@"id":self.userInfo[@"user_id"]}];
                    //通过通知中心发送通知
                    [[NSNotificationCenter defaultCenter] postNotification:notification];
                    
                }];
            }
            
        }]];
//        [alert addAction:[UIAlertAction actionWithTitle:self.alertArr[2] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//            
//        }]];
//        [alert addAction:[UIAlertAction actionWithTitle:self.alertArr[3] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//            
//        }]];
    }
    [alert addAction:[UIAlertAction actionWithTitle:self.alertArr[4] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        NSString *role;
        
        // 如果是房主操作就发送到Push
        if ([self.hostId isEqualToString:[GetUserDefaule(USERINFO) valueForKey:@"user_id"]]) {
            role = @"sendBannedMsg0";
        }
        else {
            role = @"sendBannedMsg1";
        }
        
        // 发送禁言消息通知
        NSNotification *notification =[NSNotification notificationWithName:role object:nil userInfo:@{@"id":self.userInfo[@"user_id"]}];
        //通过通知中心发送通知
        [[NSNotificationCenter defaultCenter] postNotification:notification];
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:self.alertArr[5] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        NSString *role;
        
        // 如果是房主操作就发送到Push
        if ([self.hostId isEqualToString:[GetUserDefaule(USERINFO) valueForKey:@"user_id"]]) {
            role = @"sendRemoveAudienceMsg0";
        }
        else {
            role = @"sendRemoveAudienceMsg1";
        }

        // 发送禁言消息通知
        NSNotification *notification =[NSNotification notificationWithName:role object:nil userInfo:@{@"id":self.userInfo[@"user_id"]}];
        //通过通知中心发送通知
        [[NSNotificationCenter defaultCenter] postNotification:notification];
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    
    [currVC presentViewController:alert animated:YES completion:nil];
    
}

// 弹出
-(void)exChangeOut:(UIView *)changeOutView dur:(CFTimeInterval)dur{
    
    CAKeyframeAnimation * animation;
    animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    animation.duration = dur;
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeForwards;
    NSMutableArray *values = [NSMutableArray array];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
    animation.values = values;
    animation.timingFunction = [CAMediaTimingFunction functionWithName: @"easeInEaseOut"];
    [changeOutView.layer addAnimation:animation forKey:nil];
    
}
- (void)maskClick
{
    // 取消弹框
    [UIView animateWithDuration:0.2 animations:^{
        self.alpha = 0.0;
    } completion:^(BOOL finished) {
        self.alertview = nil;
        [self removeFromSuperview];
    }];
}

- (void)initShow:(id)userInfo {
    NSLog(@"可以弹出alert");
    self.userInfo = userInfo;
    
    
    if ([self.userInfo[@"is_admin"] isEqual:@1]) {
        self.alertArr = [[NSMutableArray alloc] initWithObjects:@"管理", @"解除管理员", @"举报", @"拉黑", @"禁言", @"踢出聊天室", nil];
    }
    else
        self.alertArr = [[NSMutableArray alloc] initWithObjects:@"管理", @"设置管理员", @"举报", @"拉黑", @"禁言", @"踢出聊天室", nil];
}


@end
